<template>
  <div>
    <home-header></home-header>
    <home-swiper></home-swiper>
    <home-icons></home-icons>
    <home-hot></home-hot>
    <home-week></home-week>
  </div>
</template>

<script>
import HomeHeader from './component/Header'
import HomeSwiper from './component/Swiper'
import HomeIcons from './component/Icons'
import HomeHot from './component/Hot'
import HomeWeek from './component/Weekend'
import axios from 'axios'
import { mapState } from 'vuex'
export default {
  name: "Home",
  data() {
    return {
      lastCity: ""
    }
  },
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeHot,
    HomeWeek
  },
  computed: {
    ...mapState(["city"])
  },
  methods: {
    getHomeInfo() {
      axios
        .get('/static/json/obj.json?city=' + this.city)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc(res) {
      const res1 = res.data
      console.log(res1)
    },
  },
  mounted() {
    this.lastCity = this.city
    this.getHomeInfo()
  },
  // keep-alive标签新增的函数
  activated() {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
    }
  }
}
</script>

<style>
html,body{
  margin: 0px;
  padding: 0px;
  font-size: 50px;
}
</style>
